package com.zw.pdm.module.contact.controller;


import com.zw.pdm.base.BaseController;
import com.zw.pdm.common.JsonResult;
import com.zw.pdm.entity.sys.User;
import com.zw.pdm.module.afterSale.Service.CheckService;
import com.zw.pdm.module.afterSale.model.FileModel;
import com.zw.pdm.module.afterSale.model.ProjectModel;
import com.zw.pdm.module.contact.mapper.ProDao;
import com.zw.pdm.module.contact.model.Contact;
import com.zw.pdm.module.contact.model.DsnProStruct;
import com.zw.pdm.module.contact.model.Post;
import com.zw.pdm.module.contact.model.Project;
import com.zw.pdm.module.contact.service.ContactService;
import com.zw.pdm.module.contact.service.ProService;
import com.zw.pdm.util.ShiroUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletResponse;
import java.util.ArrayList;
import java.util.List;

import static com.zw.pdm.common.JsonResult.ResultType.ERROR;
import static com.zw.pdm.common.JsonResult.ResultType.SUCCESS;


@Controller
public class ContactController extends BaseController {


    @Autowired
    private ProService proService;
    @Autowired
    private ProDao proDao;
    @Autowired
    private ContactService contactService;
    @Autowired
    private CheckService checkService;

    /**
     * @Description: contactCreatePage 菜单跳转至创建联络单页面
     * @Author: zcb
     * @Date: 2020-12-18 13:16:59
     * @Param: [model]
     * @Return: java.lang.String
     **/
    @GetMapping("/contact/create")
    @RequiresPermissions({"lia:set:view"})
    public String contactCreatePage(Model model) {
        //1.用户即为创建人 创建人信息、部门信息
        User loginUser = ShiroUtils.getUser();
        Post post = new Post();
        Post loginUserPost =  new Post();
        if (loginUser.getId()==1){
            loginUserPost.setBranchName("");
        }else{
            post.setSysId(loginUser.getId());
            loginUserPost = contactService.getUserDeptName(post);
        }
        model.addAttribute("loginUser", loginUser);
        model.addAttribute("loginUserPost", loginUserPost);
        return "/contact/contactCreate";
    }


    /**
     * @Description: contactReturnPage 跳转联络单回复页面
     * @Author: zcb
     * @Date: 2021-01-09 11:14:02
     * @Param: [model]
     * @Return: java.lang.String
     **/
    @GetMapping("/contact/return")
    @RequiresPermissions({"lia:reply:view"})
    public String contactReturnPage(Model model) {
        return "/contact/contactReturnList";
    }


    /**
     * @Description: contactExaminePage 跳转到联络单审核页面
     * @Author: zcb
     * @Date: 2021-01-20 13:04:28
     * @Param: [model]
     * @Return: java.lang.String
     **/
    @GetMapping("/contact/examine")
    @RequiresPermissions({"lia:alter:view"})
    public String contactExaminePage(Model model) {
        return "/contact/contactExamineList";
    }

    /**
     * @Description: contactSelectPage 跳转到联络单查询页面
     * @Author: zcb
     * @Date: 2021-01-20 15:18:12
     * @Param: [model]
     * @Return: java.lang.String
     **/
    @GetMapping("/contact/select")
    @RequiresPermissions({"lia:liaison:view"})
    public String contactSelectPage(Model model) {
        return "/contact/contactSelectList";
    }

    /**
     * @Description: contactInfoEditPage 跳转 联络单编辑页面
     * @Author: zcb
     * @Date: 2021-01-09 11:13:42
     * @Param: [id, model]
     * @Return: java.lang.String
     **/
    @GetMapping("/contact/contactInfoEdit")
    @RequiresPermissions({"lia:reply:edit"})
    public String contactInfoEditPage(int detailId, Model model) {

        User user = ShiroUtils.getUser();

        /** *查看当前用户为 创建人 还是  参与人 ***************************************************
         *  todo 创建人 编辑 -> 修改创建的 联络单主表信息 及 detail表中自己数据的信息               *
         *  todo 参与人 编辑 -> 回复detail表中自己数据的 content 字段   或者  修改 content 字段值  *
         *  ***** 根据用户身份 跳转不同样式的页面*************************************************/

        /** 1.查明用户身份 */
        Contact contact = contactService.queryContactByDetailId(detailId);
        int id = contact.getConId();
        Contact cContact = contactService.queryCcontactInfoById(id); //主表信息 项目基本信息
        List<Contact> ortherOkContacts = contactService.queryOtherContents(id);//其他参与人已审核通过的信息
        List<FileModel> createFileList = checkService.selectFileInfoByDetailId(detailId, 3);//创建人附件信息
        List<Post> canYuPostList = contactService.queryCanYuPosts(id);//参与人列表
        if (contact.getConIdentity() == 1) {
            //是创建人
            /** 联络单主表信息*/
            model.addAttribute("cContact", cContact);
            /** 创建人上传的附件信息*/
            model.addAttribute("createFileList", createFileList);
            /** 创建人编辑信息*/
            model.addAttribute("contact", contact); //content 字段必有内容
            /** 参与人列表*/
            model.addAttribute("canYuPostList", canYuPostList);
            /** 登录用户身份  部门信息*/
            User createUser = ShiroUtils.getUser();
            Post post = new Post();
            post.setSysId(user.getId());
            Post createUserPost = contactService.getUserDeptName(post);
            model.addAttribute("createUser", createUser);
            model.addAttribute("createUserPost", createUserPost);

            List<DsnProStruct> structList = proService.findPartByProjectCode(contact.getProCode(), contact.getSpecial());
            model.addAttribute("structList", structList);

            User loginUser = ShiroUtils.getUser();
            model.addAttribute("loginUser", loginUser);
            return "/contact/contactEdit1";
        } else {
            //是参与人
            /** 已审核通过的其他参与人信息 (包含附件列表)*/
            for (int i = 0; i < ortherOkContacts.size(); i++) {
                List<FileModel> canYufileList = checkService.selectFileInfoByDetailId(ortherOkContacts.get(i).getDetailId(), 3);
                //todo 编制人 审核人  部门   编制时间等，，，，信息
                Post post = proDao.queryUserPostInfo(ortherOkContacts.get(i).getEditId2());
                ortherOkContacts.get(i).setPost(post);
                ortherOkContacts.get(i).setDetailFileList(canYufileList);//参与人附件信息
            }
            model.addAttribute("ortherOkContacts", ortherOkContacts);
            /** 联络单主表信息*/
            model.addAttribute("cContact", cContact);
            /** 用户编辑的信息及上传的附件（待审核内容）*/
            List<FileModel> userfileList = checkService.selectFileInfoByDetailId(detailId, 3);
            Post post = proDao.queryUserPostInfo(contact.getEditId2());
            if (post != null) {
                contact.setPost(post);
            }
            contact.setDetailFileList(userfileList);
            model.addAttribute("contact", contact);
            /** 创建人编辑信息*/
            /**此时的 detailid 是该参与人的detailid   要以此查找创建人的detailid */
            Contact createContact = contactService.queryCreateInfo(detailId);
            Post postCreate = proDao.queryUserPostInfo(createContact.getEditId1());
            createContact.setPost(postCreate);
            //todo 编制人 审核人  部门   编制时间等，，，，信息
            model.addAttribute("createContact", createContact); //content 字段必有内容
            /** 创建人上传的附件信息*/
            List<FileModel> createFileList2 = checkService.selectFileInfoByDetailId(createContact.getDetailId(), 3);//创建人附件信息
            model.addAttribute("createFileList2", createFileList2);
            /** 参与人列表*/
            model.addAttribute("canYuPostList", canYuPostList);

            return "/contact/contactEdit2";
        }

    }


    /**
     * @Description: contactInfoSelectPage 跳转查看页面（回复页中查看）
     * @Author: zcb
     * @Date: 2021-01-20 09:58:22
     * @Param: [detailId, model]
     * @Return: java.lang.String
     **/
    @GetMapping("/contact/contactInfoSelect")
    //@RequiresPermissions({"basic:dept:view"})
    public String contactInfoSelectPage(int detailId, Model model) {

        User user = ShiroUtils.getUser();

        /** *查看当前用户为 创建人 还是  参与人 ***************************************************
         *  todo 创建人 编辑 -> 修改创建的 联络单主表信息 及 detail表中自己数据的信息               *
         *  todo 参与人 编辑 -> 回复detail表中自己数据的 content 字段   或者  修改 content 字段值  *
         *  ***** 根据用户身份 跳转不同样式的页面*************************************************/

        /** 1.查明用户身份 */
        Contact contact = contactService.queryContactByDetailId(detailId);
        int id = contact.getConId();
        Contact cContact = contactService.queryCcontactInfoById(id); //主表信息 项目基本信息
        List<Contact> ortherOkContacts = contactService.queryOtherContents(id);//其他参与人已审核通过的信息
        List<Post> canYuPostList = contactService.queryCanYuPosts(id);//参与人列表

        /** 已审核通过的其他参与人信息 (包含附件列表)*/
        for (int i = 0; i < ortherOkContacts.size(); i++) {
            List<FileModel> canYufileList = checkService.selectFileInfoByDetailId(ortherOkContacts.get(i).getDetailId(), 3);
            //todo 编制人 审核人  部门   编制时间等，，，，信息
            Post post = proDao.queryUserPostInfo(ortherOkContacts.get(i).getEditId2());
            ortherOkContacts.get(i).setPost(post);
            ortherOkContacts.get(i).setDetailFileList(canYufileList);//参与人附件信息
        }
        model.addAttribute("ortherOkContacts", ortherOkContacts);
        /** 联络单主表信息*/
        model.addAttribute("cContact", cContact);
        /** 用户编辑的信息及上传的附件*/
        List<FileModel> userfileList = checkService.selectFileInfoByDetailId(detailId, 3);
        contact.setDetailFileList(userfileList);
        model.addAttribute("contact", contact);
        /** 创建人编辑信息*/
        /**此时的 detailid 是该参与人的detailid   要以此查找创建人的detailid */
        Contact createContact = contactService.queryCreateInfo(detailId);
        Post postCreate = proDao.queryUserPostInfo(createContact.getEditId1());
        createContact.setPost(postCreate);
        //todo 编制人 审核人  部门   编制时间等，，，，信息
        model.addAttribute("createContact", createContact); //content 字段必有内容
        /** 创建人上传的附件信息*/
        List<FileModel> createFileList2 = checkService.selectFileInfoByDetailId(createContact.getDetailId(), 3);//创建人附件信息
        model.addAttribute("createFileList2", createFileList2);
        /** 参与人列表*/
        model.addAttribute("canYuPostList", canYuPostList);
        /** 登录用户身份  部门信息*/
        User createUser2 = ShiroUtils.getUser();
        Post post = new Post();
        post.setSysId(user.getId());
        Post createUserPost2 = contactService.getUserDeptName(post);
        model.addAttribute("createUser2", createUser2);
        model.addAttribute("createUserPost2", createUserPost2);
        return "/contact/contactSelect";
    }


    /**
     * @Description: contactInfoExaminePage 跳转审核页面
     * @Author: zcb
     * @Date: 2021-01-20 09:59:13
     * @Param: [detailId, model]
     * @Return: java.lang.String
     **/
    @GetMapping("/contact/contactInfoExamine")
    @RequiresPermissions({"lia:alter:check"})
    public String contactInfoExaminePage(int detailId, Model model) {

        User user = ShiroUtils.getUser();

        /** *查看当前用户为 创建人 还是  参与人 ***************************************************
         *  todo 创建人 编辑 -> 修改创建的 联络单主表信息 及 detail表中自己数据的信息               *
         *  todo 参与人 编辑 -> 回复detail表中自己数据的 content 字段   或者  修改 content 字段值  *
         *  ***** 根据用户身份 跳转不同样式的页面*************************************************/

        /** 1.查明用户身份 */
        Contact contact = contactService.queryContactByDetailId(detailId);
        int id = contact.getConId();
        Contact cContact = contactService.queryCcontactInfoById(id); //主表信息 项目基本信息
        List<Contact> ortherOkContacts = contactService.queryOtherContents(id);//其他参与人已审核通过的信息
        List<Post> canYuPostList = contactService.queryCanYuPosts(id);//参与人列表

        /** 已审核通过的其他参与人信息 (包含附件列表)*/
        for (int i = 0; i < ortherOkContacts.size(); i++) {
            List<FileModel> canYufileList = checkService.selectFileInfoByDetailId(ortherOkContacts.get(i).getDetailId(), 3);
            Post post = proDao.queryUserPostInfo(ortherOkContacts.get(i).getEditId2());
            ortherOkContacts.get(i).setPost(post);// 编制人 时间。。等信息
            ortherOkContacts.get(i).setDetailFileList(canYufileList);//参与人附件信息
        }
        model.addAttribute("ortherOkContacts", ortherOkContacts);
        /** 联络单主表信息*/
        model.addAttribute("cContact", cContact);

        /** 创建人编辑信息*/
        /** 此时的 detailid 是该参与人的detailid   要以此查找创建人的detailid */
        Contact createContact = contactService.queryCreateInfo(detailId);
        Post postCreate = proDao.queryUserPostInfo(createContact.getEditId1());
        createContact.setPost(postCreate);// 编制人 时间。。等信息
        model.addAttribute("createContact", createContact); //content 字段必有内容
        /** 创建人上传的附件信息*/
        List<FileModel> createFileList2 = checkService.selectFileInfoByDetailId(createContact.getDetailId(), 3);//创建人附件信息
        model.addAttribute("createFileList2", createFileList2);

        /** 参与人列表*/
        model.addAttribute("canYuPostList", canYuPostList);

        /** 用户编辑的信息及上传的附件（待审核内容）*/
        List<FileModel> userfileList = checkService.selectFileInfoByDetailId(detailId, 3);
        Post post = proDao.queryUserPostInfo(contact.getEditId2());
        contact.setPost(post);
        contact.setDetailFileList(userfileList);
        model.addAttribute("contact", contact);
        model.addAttribute("detailId", detailId);
        if (contact.getConIdentity() == 1) {
            return "/contact/contactExamine1";
        } else {
            return "/contact/contactExamine2";
        }
    }


    /**
     * @Description: contactExamSelectPage
     * @Author: zcb
     * @Date: 2021-01-21 13:44:14
     * @Param: [detailId, model]
     * @Return: java.lang.String
     **/
    @GetMapping("/contact/contactReturnSelect")
    //@RequiresPermissions({"basic:dept:view"})
    public String contactReturnSelectPage(int detailId, Model model) {

        User user = ShiroUtils.getUser();

        /** *查看当前用户为 创建人 还是  参与人 ***************************************************
         *  todo 创建人 编辑 -> 修改创建的 联络单主表信息 及 detail表中自己数据的信息               *
         *  todo 参与人 编辑 -> 回复detail表中自己数据的 content 字段   或者  修改 content 字段值  *
         *  ***** 根据用户身份 跳转不同样式的页面*************************************************/

        /** 1.查明用户身份 */
        Contact contact = contactService.queryContactByDetailId(detailId);
        int id = contact.getConId();
        Contact cContact = contactService.queryCcontactInfoById(id); //主表信息 项目基本信息
        List<Contact> ortherOkContacts = contactService.queryOtherContents(id);//其他参与人已审核通过的信息
        List<Post> canYuPostList = contactService.queryCanYuPosts(id);//参与人列表

        /** 已审核通过的其他参与人信息 (包含附件列表)*/
        for (int i = 0; i < ortherOkContacts.size(); i++) {
            List<FileModel> canYufileList = checkService.selectFileInfoByDetailId(ortherOkContacts.get(i).getDetailId(), 3);
            Post post = proDao.queryUserPostInfo(ortherOkContacts.get(i).getEditId2());
            ortherOkContacts.get(i).setPost(post);// 编制人 时间。。等信息
            ortherOkContacts.get(i).setDetailFileList(canYufileList);//参与人附件信息
        }
        model.addAttribute("ortherOkContacts", ortherOkContacts);
        /** 联络单主表信息*/
        model.addAttribute("cContact", cContact);

        /** 创建人编辑信息*/
        /** 此时的 detailid 是该参与人的detailid   要以此查找创建人的detailid */
        Contact createContact = contactService.queryCreateInfo(detailId);
        Post postCreate = proDao.queryUserPostInfo(createContact.getEditId1());
        createContact.setPost(postCreate);// 编制人 时间。。等信息
        model.addAttribute("createContact", createContact); //content 字段必有内容
        /** 创建人上传的附件信息*/
        List<FileModel> createFileList2 = checkService.selectFileInfoByDetailId(createContact.getDetailId(), 3);//创建人附件信息
        model.addAttribute("createFileList2", createFileList2);

        /** 参与人列表*/
        model.addAttribute("canYuPostList", canYuPostList);

        /** 用户编辑的信息及上传的附件（待审核内容）*/
        List<FileModel> userfileList = checkService.selectFileInfoByDetailId(detailId, 3);
        Post post = proDao.queryUserPostInfo(contact.getEditId2());
        contact.setPost(post);
        contact.setDetailFileList(userfileList);
        model.addAttribute("contact", contact);
        model.addAttribute("detailId", detailId);
        if (contact.getConIdentity() == 1) {
            return "/contact/contactReSelect1";
        } else {
            return "/contact/contactReSelect2";
        }
    }


    /**
     * @Description: proList 输入项目编号 带回项目名称、数量
     * @Author: zcb
     * @Date: 2020-12-21 14:02:44
     * @Param: [q]
     **/
    @GetMapping("/project/select")
    @ResponseBody
    public List<Project> proList(String q) {
        return proService.findProjectByCode(q);
    }

    /**
     * @Description: partList 查询专业、部分
     * @Author: zcb
     * @Date: 2020-12-22 08:29:36
     * @Param: [code, type]
     **/
    @GetMapping("/part/list")
    @ResponseBody
    public List<DsnProStruct> partList(String code, String type) {
        return proService.findPartByProjectCode(code, type);
    }


    /**
     * @Description: deptList 查询“科长”列表
     * @Author: zcb
     * @Date: 2020-12-22 15:31:13
     * @Param: []
     **/
    @PostMapping("deptList/select")
    @ResponseBody
    public JsonResult deptList() {
        return jsonResult(proService.selectDeptList());
    }


    /**
     * @Description: joinList 参与人列表
     * @Author: zcb
     * @Date: 2021-01-11 20:23:32
     * @Param: [id]
     * @Return: com.zhongwang.sale.common.JsonResult
     **/
    @PostMapping("joinList/select")
    @ResponseBody
    public JsonResult joinList(int id) {
        return jsonResult(contactService.queryRcontactInfoByCid(id));
    }


    /**
     * @Description: saleProList 项目信息 模糊查询下拉框
     * @Author: zcb
     * @Date: 2021-01-08 09:34:20
     * @Param: [proCode]
     * @Return: java.util.List<com.zhongwang.sale.module.contact.model.Project>
     **/
    @ResponseBody
    @GetMapping("inputTest")
    public List<String> input(String proCode) {
        List<ProjectModel> model = contactService.selectLikeProCode(proCode);
        List<String> list = new ArrayList<>();
        for (int i = 0; i < model.size(); i++) {
            list.add(model.get(i).getProCode());
        }
        return list;
    }

    /**
     * @Description: proInfo 项目信息 填充其他基本信息
     * @Author: zcb
     * @Date: 2021-01-08 13:04:00
     * @Param: [arg]
     * @Return: com.zhongwang.sale.common.JsonResult
     **/
    @ResponseBody
    @PostMapping("selectProInfo")
    public JsonResult proInfo(String arg) {
        JsonResult jsonResult = new JsonResult();
        jsonResult.setData(contactService.selectProInfoByCode(arg));
        jsonResult.setType(SUCCESS);
        return jsonResult;
    }


    /**
     * @Description: newContact 创建联络单
     * @Author: zcb
     * @Date: 2021-01-08 14:38:41
     * @Param: [canYuBranchIdList, content, proId, proCode, proName, proQty, special, proPartId, questionType, customer, insSite, fileUrl, fileName]
     * @Return: com.zhongwang.sale.common.JsonResult
     **/
    @ResponseBody
    @PostMapping("newContact")
    public JsonResult newContact(String canYuBranchIdList,
                                 String content,
                                 String proId,
                                 String proCode,
                                 String proName,
                                 String proQty,
                                 String special,
                                 String proPart,
                                 String conType,
                                 String customer,
                                 String insSite,
                                 String fileUrl[],
                                 String fileName[],
                                 String postTel) {
        JsonResult jsonResult = new JsonResult();
        int i = contactService.newContact(canYuBranchIdList, content, proId, proCode, proName, proQty, special, proPart, conType, customer, insSite, fileUrl, fileName,postTel);
        if (i == 1) {
            jsonResult.setMsg("保存成功");
            jsonResult.setType(SUCCESS);
            return jsonResult;
        } else {
            jsonResult.setMsg("保存失败，请联系管理员");
            jsonResult.setType(ERROR);
            return jsonResult;
        }
    }


    /**
     * @Description: EditContact 创建人 编辑联络单
     * @Author: zcb
     * @Date: 2021-01-12 12:52:13
     * @Param: [canYuBranchIdList, content, proId, proCode, proName, proQty, special, proPartId, questionType, customer, insSite, fileUrl, fileName, fileId]
     * @Return: com.zhongwang.sale.common.JsonResult
     **/
    @ResponseBody
    @PostMapping("editContact1")
    public JsonResult EditContact1(Integer dsnContactId, String canYuBranchIdList, String content, Integer proId,
                                   String proCode, String proName, Integer proQty, String special, String proPart,
                                   String questionType, String customer, String insSite, String fileUrl[], String fileName[],
                                   String fileId[]) {
        JsonResult jsonResult = new JsonResult();
        String msg = contactService.EditContact1(dsnContactId, canYuBranchIdList, content, proId, proCode, proName, proQty, special, proPart, questionType, customer, insSite, fileUrl, fileName, fileId);
        if (msg.equals("修改成功")) {
            jsonResult.setMsg(msg);
            jsonResult.setType(SUCCESS);
            return jsonResult;
        } else {
            jsonResult.setMsg("修改失败，请联系管理员");
            jsonResult.setType(ERROR);
            return jsonResult;
        }

    }

    /**
     * @Description: EditContact2 参与人 联络单编辑
     * @Author: zcb
     * @Date: 2021-01-19 09:28:59
     * @Param: [dsnContactId, canYuBranchIdList, content, proId, proCode, proName, proQty, special, proPartId, questionType, customer, insSite, fileUrl, fileName, fileId]
     * @Return: com.zhongwang.sale.common.JsonResult
     **/
    @ResponseBody
    @PostMapping("editContact2")
    public JsonResult EditContact2(Integer dsnContactId, String content, String fileUrl[], String fileName[], String fileId[],String postTel) {
        JsonResult jsonResult = new JsonResult();

        String msg = contactService.EditContact2(dsnContactId, content, fileUrl, fileName, fileId,postTel);
        if (msg.equals("修改成功")) {
            jsonResult.setMsg(msg);
            jsonResult.setType(SUCCESS);
            return jsonResult;
        } else {
            jsonResult.setMsg("修改失败，请联系管理员");
            jsonResult.setType(ERROR);
            return jsonResult;
        }
    }


    /**
     * @Description: queryContactList 联络单回复 页面列表查询
     * @Author: zcb
     * @Date: 2021-01-09 10:09:46
     * @Param: [contactModel]
     * @Return: com.zhongwang.sale.common.JsonResult
     **/
    @ResponseBody
    @PostMapping("queryContactList")
//    @RequiresPermissions(value = {"report:out:edit", "report:ass:edit", "report:mal:edit"}, logical = Logical.OR)
    public JsonResult ContactList(Contact contact) {
//        startPage();
        User user = ShiroUtils.getUser();
        contact.setLoginId(user.getId());
        return jsonResult(contactService.queryContactList(contact));
    }


    /**
     * @Description: ContactExamineList 联络单审核 页面列表查询
     * @Author: zcb
     * @Date: 2021-01-20 10:05:12
     * @Param: [contact]
     * @Return: com.zhongwang.sale.common.JsonResult
     **/
    @ResponseBody
    @PostMapping("queryContactExamineList")
//    @RequiresPermissions(value = {"report:out:edit", "report:ass:edit", "report:mal:edit"}, logical = Logical.OR)
    public JsonResult ContactExamineList(Contact contact) {
//        startPage();
        User user = ShiroUtils.getUser();
        contact.setLoginId(user.getId());
        return jsonResult(contactService.queryContactExamineList(contact));
    }


    /**
     * @Description: ContactSelectList 联络单查询 页面列表查询
     * @Author: zcb
     * @Date: 2021-01-20 15:24:23
     * @Param: [contact]
     * @Return: com.zhongwang.sale.common.JsonResult
     **/
    @ResponseBody
    @PostMapping("queryContactSelectList")
//    @RequiresPermissions(value = {"report:out:edit", "report:ass:edit", "report:mal:edit"}, logical = Logical.OR)
    public JsonResult ContactSelectList(Contact contact) {
//        startPage();
        User user = ShiroUtils.getUser();
        contact.setLoginId(user.getId());
        return jsonResult(contactService.queryContactSelectList(contact));
    }


    /**
     * @Description: checkDelFile 联络单删除
     * @Author: zcb
     * @Date: 2021-01-13 12:51:57
     * @Param: [fileId]
     * @Return: java.lang.String
     **/
    @ResponseBody
    @PostMapping("contact/delContact")
    @RequiresPermissions({"lia:reply:del"})
    public JsonResult contactDel(Integer id) {
        JsonResult jsonResult = new JsonResult();
        String result = contactService.delContactById(id);
        if (result.equals("删除成功")) {
            jsonResult.setMsg(result);
            jsonResult.setType(SUCCESS);
            return jsonResult;
        } else {
            jsonResult.setMsg(result);
            jsonResult.setType(ERROR);
            return jsonResult;
        }
    }


    /**
     * @Description: contactFileDown 附件下载
     * @Author: zcb
     * @Date: 2021-01-13 13:16:21
     * @Param: [fileUrl, fileName]
     * @Return: com.zhongwang.sale.common.JsonResult
     **/

    @GetMapping("contact/fileDown")
    public void contactFileDown(String fileUrl, HttpServletResponse httpServletResponse) {
        contactService.downLoadFile(fileUrl, httpServletResponse);
    }


    /**
     * @Description: contactSubmit 联络单提交
     * @Author: zcb
     * @Date: 2021-01-20 09:24:57
     * @Param: [detailId]
     * @Return: com.zhongwang.sale.common.JsonResult
     **/
    @ResponseBody
    @PostMapping("contact/submit")
    @RequiresPermissions({"lia:reply:submit"})
    public JsonResult contactSubmit(Integer detailId) {
        JsonResult jsonResult = new JsonResult();
//        String a = contactService.submitFandDetailContet(detailId);
//        if(StringUtils.isEmpty(a)){
//            jsonResult.setMsg("回复内容没有编辑不能提交！");
//            jsonResult.setType(ERROR);
//            return jsonResult;
//        }
        int i = contactService.submitContactById(detailId);
        if (i == 1) {
            jsonResult.setMsg("提交成功");
            jsonResult.setType(SUCCESS);
            return jsonResult;
        } else {
            jsonResult.setMsg("提交失败！");
            jsonResult.setType(ERROR);
            return jsonResult;
        }
    }

    /**
     * @Description: contactAgreeContact 审核通过
     * @Author: zcb
     * @Date: 2021-01-20 13:06:34
     * @Param: [detailId]
     * @Return: com.zhongwang.sale.common.JsonResult
     **/
    @ResponseBody
    @PostMapping("contact/agreeContact")
    public JsonResult contactAgreeContact(Integer detailId) {
        JsonResult jsonResult = new JsonResult();
        int i = contactService.contactAgreeContact(detailId);
        if (i == 1) {
            jsonResult.setMsg("操作成功");
            jsonResult.setType(SUCCESS);
            return jsonResult;
        } else {
            jsonResult.setMsg("操作失败！");
            jsonResult.setType(ERROR);
            return jsonResult;
        }
    }

    /**
     * @Description: contactRefuseContact 审核驳回
     * @Author: zcb
     * @Date: 2021-01-21 13:17:37
     * @Param: [detailId]
     * @Return: com.zhongwang.sale.common.JsonResult
     **/
    @ResponseBody
    @PostMapping("contact/refuseContact")
    public JsonResult contactRefuseContact(Integer detailId, String examineOpin) {
        JsonResult jsonResult = new JsonResult();
        int i = contactService.contactRefuseContact(detailId, examineOpin);
        if (i == 1) {
            jsonResult.setMsg("操作成功");
            jsonResult.setType(SUCCESS);
            return jsonResult;
        } else {
            jsonResult.setMsg("操作失败！");
            jsonResult.setType(ERROR);
            return jsonResult;
        }
    }


}
